from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-29 14:02:40.953229
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 29, Nov, 2022
Time: 14:02:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0860
Nobs: 855.000 HQIC: -51.3946
Log likelihood: 11224.3 FPE: 3.94868e-23
AIC: -51.5861 Det(Omega_mle): 3.55633e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298848 0.050201 5.953 0.000
L1.Burgenland 0.109784 0.034510 3.181 0.001
L1.Kärnten -0.106045 0.018381 -5.769 0.000
L1.Niederösterreich 0.210638 0.072136 2.920 0.004
L1.Oberösterreich 0.099847 0.068487 1.458 0.145
L1.Salzburg 0.251618 0.036588 6.877 0.000
L1.Steiermark 0.037273 0.047961 0.777 0.437
L1.Tirol 0.107451 0.038883 2.763 0.006
L1.Vorarlberg -0.059760 0.033516 -1.783 0.075
L1.Wien 0.054649 0.061250 0.892 0.372
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067701 0.103542 0.654 0.513
L1.Burgenland -0.030151 0.071179 -0.424 0.672
L1.Kärnten 0.047528 0.037912 1.254 0.210
L1.Niederösterreich -0.172313 0.148784 -1.158 0.247
L1.Oberösterreich 0.376326 0.141257 2.664 0.008
L1.Salzburg 0.288392 0.075464 3.822 0.000
L1.Steiermark 0.108942 0.098921 1.101 0.271
L1.Tirol 0.316678 0.080198 3.949 0.000
L1.Vorarlberg 0.023292 0.069128 0.337 0.736
L1.Wien -0.020014 0.126330 -0.158 0.874
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197806 0.026000 7.608 0.000
L1.Burgenland 0.092511 0.017874 5.176 0.000
L1.Kärnten -0.008694 0.009520 -0.913 0.361
L1.Niederösterreich 0.268588 0.037361 7.189 0.000
L1.Oberösterreich 0.114907 0.035471 3.239 0.001
L1.Salzburg 0.052621 0.018950 2.777 0.005
L1.Steiermark 0.016719 0.024840 0.673 0.501
L1.Tirol 0.098511 0.020138 4.892 0.000
L1.Vorarlberg 0.056189 0.017359 3.237 0.001
L1.Wien 0.111871 0.031723 3.527 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105182 0.026671 3.944 0.000
L1.Burgenland 0.047303 0.018334 2.580 0.010
L1.Kärnten -0.017424 0.009766 -1.784 0.074
L1.Niederösterreich 0.196854 0.038324 5.137 0.000
L1.Oberösterreich 0.280042 0.036385 7.697 0.000
L1.Salzburg 0.120201 0.019438 6.184 0.000
L1.Steiermark 0.101508 0.025480 3.984 0.000
L1.Tirol 0.123900 0.020658 5.998 0.000
L1.Vorarlberg 0.068798 0.017806 3.864 0.000
L1.Wien -0.027194 0.032541 -0.836 0.403
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131083 0.048363 2.710 0.007
L1.Burgenland -0.049588 0.033247 -1.492 0.136
L1.Kärnten -0.039472 0.017708 -2.229 0.026
L1.Niederösterreich 0.167232 0.069495 2.406 0.016
L1.Oberösterreich 0.141033 0.065979 2.138 0.033
L1.Salzburg 0.284203 0.035248 8.063 0.000
L1.Steiermark 0.033156 0.046205 0.718 0.473
L1.Tirol 0.163042 0.037459 4.353 0.000
L1.Vorarlberg 0.104232 0.032288 3.228 0.001
L1.Wien 0.066607 0.059007 1.129 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058437 0.038225 1.529 0.126
L1.Burgenland 0.042643 0.026277 1.623 0.105
L1.Kärnten 0.049879 0.013996 3.564 0.000
L1.Niederösterreich 0.227698 0.054927 4.145 0.000
L1.Oberösterreich 0.271541 0.052148 5.207 0.000
L1.Salzburg 0.058271 0.027859 2.092 0.036
L1.Steiermark -0.007111 0.036519 -0.195 0.846
L1.Tirol 0.156123 0.029607 5.273 0.000
L1.Vorarlberg 0.068423 0.025520 2.681 0.007
L1.Wien 0.074708 0.046638 1.602 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185396 0.045754 4.052 0.000
L1.Burgenland -0.004510 0.031453 -0.143 0.886
L1.Kärnten -0.060859 0.016753 -3.633 0.000
L1.Niederösterreich -0.086727 0.065746 -1.319 0.187
L1.Oberösterreich 0.191969 0.062420 3.075 0.002
L1.Salzburg 0.059680 0.033347 1.790 0.074
L1.Steiermark 0.225739 0.043712 5.164 0.000
L1.Tirol 0.494820 0.035438 13.963 0.000
L1.Vorarlberg 0.047811 0.030547 1.565 0.118
L1.Wien -0.051284 0.055824 -0.919 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158624 0.052124 3.043 0.002
L1.Burgenland -0.009125 0.035832 -0.255 0.799
L1.Kärnten 0.064898 0.019085 3.400 0.001
L1.Niederösterreich 0.203192 0.074899 2.713 0.007
L1.Oberösterreich -0.067064 0.071110 -0.943 0.346
L1.Salzburg 0.222358 0.037989 5.853 0.000
L1.Steiermark 0.113353 0.049798 2.276 0.023
L1.Tirol 0.083976 0.040372 2.080 0.038
L1.Vorarlberg 0.122265 0.034799 3.513 0.000
L1.Wien 0.109347 0.063596 1.719 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356738 0.030747 11.602 0.000
L1.Burgenland 0.008846 0.021137 0.419 0.676
L1.Kärnten -0.024707 0.011258 -2.195 0.028
L1.Niederösterreich 0.228372 0.044182 5.169 0.000
L1.Oberösterreich 0.156710 0.041946 3.736 0.000
L1.Salzburg 0.052950 0.022409 2.363 0.018
L1.Steiermark -0.017885 0.029375 -0.609 0.543
L1.Tirol 0.117701 0.023815 4.942 0.000
L1.Vorarlberg 0.072192 0.020528 3.517 0.000
L1.Wien 0.050455 0.037514 1.345 0.179
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043785 0.161187 0.191852 0.165220 0.132140 0.124431 0.070125 0.231372
Kärnten 0.043785 1.000000 0.002315 0.131815 0.045567 0.099004 0.427361 -0.050637 0.102218
Niederösterreich 0.161187 0.002315 1.000000 0.344713 0.167523 0.310603 0.128174 0.192358 0.341440
Oberösterreich 0.191852 0.131815 0.344713 1.000000 0.235089 0.339895 0.177231 0.179532 0.274873
Salzburg 0.165220 0.045567 0.167523 0.235089 1.000000 0.151763 0.144682 0.152574 0.141342
Steiermark 0.132140 0.099004 0.310603 0.339895 0.151763 1.000000 0.163269 0.148392 0.092472
Tirol 0.124431 0.427361 0.128174 0.177231 0.144682 0.163269 1.000000 0.122209 0.163941
Vorarlberg 0.070125 -0.050637 0.192358 0.179532 0.152574 0.148392 0.122209 1.000000 0.019842
Wien 0.231372 0.102218 0.341440 0.274873 0.141342 0.092472 0.163941 0.019842 1.000000